package com.example.wanglong.myoneapplication.activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;

import com.example.wanglong.myoneapplication.R;
import com.example.wanglong.myoneapplication.common.BaseActivity;
import com.example.wanglong.myoneapplication.reparentclass.ReToast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by wang.long on 2016/4/8.
 */
public class Suppliers extends BaseActivity implements View.OnClickListener {

    private RelativeLayout exidvisatypedialog;
    private RelativeLayout exidvisatypecancel;
    private RelativeLayout exidvisatypesave;
    private LinearLayout allpage;

    private ListView supplierscontent;
    private static final String[] strs = new String[] {"不限", "上海前进因私出入境服务有限公司", "上海外经贸出入境服务有限公司", "北京卓越国际旅行社有限公司上海分公司", "中国国旅（广东）国际旅行社股份有限公司"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.suppliers_dialog);

        exidvisatypedialog=(RelativeLayout) findViewById(R.id.exidvisatypedialog);
        exidvisatypecancel=(RelativeLayout) findViewById(R.id.exidvisatypecancel);
        exidvisatypesave=(RelativeLayout) findViewById(R.id.exidvisatypesave);
        allpage=(LinearLayout) findViewById(R.id.allpage);
        supplierscontent=(ListView) findViewById(R.id.supplierscontent);

        exidvisatypedialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
            }
        });

        exidvisatypecancel.setOnClickListener(this);

        exidvisatypesave.setOnClickListener(this);

        allpage.setOnClickListener(this);

        //初始化
        initData();

    }


    public void initData(){

        supplierscontent.setAdapter(new ArrayAdapter<String>(this,R.layout.suppliers_list_item, strs));


        supplierscontent.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String desc=strs[position];
                ReToast.showToast(desc,Suppliers.this);
            }
        });
    }


    @Override
    public void onClick(View v){
        switch (v.getId()){
            case R.id.exidvisatypecancel:
                operate("1");
                break;
            case R.id.exidvisatypesave:
                operate("2");
                break;
            case R.id.allpage:
                operate("3");
                break;

        }
    }


    public void operate(String desc){

        switch (desc){
            case "1":
                ReToast.showToast("清空筛选", Suppliers.this);
                break;
            case "2":
                SharedPreferences pref=getSharedPreferences("data",MODE_PRIVATE);
                String data=pref.getString("visatype","");
                ReToast.showToast(data, Suppliers.this);
                break;
            case "3":
                ReToast.showToast(desc, Suppliers.this);
                break;
        }
        finish();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    }


}
